package com.deer.wms.system.manage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.deer.wms.project.root.service.SuperServiceImpl;
import com.deer.wms.project.root.util.DateUtils;
import com.deer.wms.project.root.util.PinYinUtil;
import com.deer.wms.system.manage.dao.WareInfoMapper;
import com.deer.wms.system.manage.model.ware.WareInfo;
import com.deer.wms.system.manage.model.ware.WareInfoCriteria;
import com.deer.wms.system.manage.model.ware.WareInfoDto;
import com.deer.wms.system.manage.model.ware.WareInfoDto2;
import com.deer.wms.system.manage.service.WareInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 *
 * @author guo
 * @since 2019/11/06
 */
@Service
@Transactional
public class WareInfoServiceImpl extends SuperServiceImpl<WareInfoMapper, WareInfo> implements WareInfoService {

    @Autowired
    private WareInfoMapper wareInfoMapper;

    @Override
    public void deleteByCodeAndCom(WareInfoCriteria criteria) {
        wareInfoMapper.deleteByCodeAndCom(criteria);
    }

    @Override
    public List<WareInfoDto2> findByName(String wareName) {
        return wareInfoMapper.findByName(wareName);
    }

    @Override
    public List<WareInfoDto> findList(WareInfoCriteria criteria) {
        return wareInfoMapper.findList(criteria);
    }

    @Override
    public List<WareInfoDto2> findSome(WareInfoCriteria criteria) {
        return wareInfoMapper.findSome(criteria);
    }

    /***
     *
     * @param wareInfo
     * @return
     */
    @Override
    public WareInfo createWare(WareInfoDto wareInfo) {
        /**
         * 新建仓库
         */
        String  nowDate = DateUtils.getNowDateTimeString();
        wareInfo.setAddTime(nowDate);
        String code = PinYinUtil.getPinYinHeadChar(wareInfo.getWareName());
        wareInfo.setWareCode(code);
        save(wareInfo);
        return wareInfo;
    }

    public WareInfo findBy(String fieldName, String value) {
        QueryWrapper<WareInfo> qw = new QueryWrapper<>();
        return this.getOne(qw.eq(fieldName, value));

    }
}
